package com.sc.servlet.user.field;

import com.alibaba.fastjson.JSON;
import com.sc.pojo.Field;
import com.sc.pojo.PageBean;
import com.sc.services.FieldServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @description: 分页查询
 * @author: sc
 * @create: 2023-01-06 17:32
 **/
@WebServlet("/selectByPage")
public class selectByPageServlet extends HttpServlet {

    private FieldServices fieldServices = new FieldServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接受页码 和每一页展示条数
        String _currentPage = request.getParameter("currentPage");
        int currentPage = Integer.parseInt(_currentPage);
        PageBean pageBean = fieldServices.selectByPage(currentPage, 3);

        String s = JSON.toJSONString(pageBean);

        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(s);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}